<template>
	<view class="container">
		<view class="content">
			<image class="logo" :src="config.staticUrl + '/srv/static/medical-logo.png'" mode="aspectFit"></image>
			<view class="title">欢迎参加抽奖活动</view>
			<view class="subtitle">填写问卷信息即可参与抽奖</view>
		</view>
		
		<!-- 隐私协议弹窗 -->
		<uni-popup ref="privacyPopup" type="center" :mask-click="false">
			<view class="privacy-popup">
				<view class="popup-title">隐私协议</view>
				<scroll-view scroll-y class="popup-content">
					<text class="content-text">欢迎使用我们的抽奖小程序。在您使用我们的服务之前，请仔细阅读《隐私协议》。我们将严格按照协议内容保护您的个人信息。</text>
					<view class="privacy-items">
						<view class="privacy-item">1. 我们收集的信息包括：姓名、手机号、公司名称、职位等必要信息。</view>
						<view class="privacy-item">2. 这些信息将用于：活动参与资格验证、活动通知和奖品发放。</view>
						<view class="privacy-item">3. 我们承诺对您的个人信息进行严格保密，不会用于其他商业用途。</view>
					</view>
					<view class="privacy-link" @click="goToPrivacy">查看完整隐私协议 ></view>
				</scroll-view>
				<view class="popup-buttons">
					<button class="btn btn-cancel" @click="rejectPrivacy">暂不使用</button>
					<button class="btn btn-confirm" @click="acceptPrivacy">同意并继续</button>
				</view>
			</view>
		</uni-popup>
	</view>
</template>

<script>
	import config from '@/config.js'
	
	export default {
		data() {
			return {
				title: 'Hello',
				config: config
			}
		},
		onLoad() {
			// 只弹窗，不自动跳转
			const hasAgreed = uni.getStorageSync('privacyAgreed')
			if (!hasAgreed) {
				// 使用setTimeout确保组件已加载
				setTimeout(() => {
					if (this.$refs.privacyPopup) {
						this.$refs.privacyPopup.open()
					}
				}, 100)
			}
		},
		methods: {
			acceptPrivacy() {
				uni.setStorageSync('privacyAgreed', true)
				if (this.$refs.privacyPopup) {
					this.$refs.privacyPopup.close()
				}
				// 延迟跳转，确保弹窗关闭动画完成
				setTimeout(() => {
					this.startLottery()
				}, 300)
			},
			rejectPrivacy() {
				if (this.$refs.privacyPopup) {
					this.$refs.privacyPopup.close()
				}
				uni.showModal({
					title: '提示',
					content: '需要同意隐私协议才能使用小程序，是否重新查看？',
					confirmText: '重新查看',
					cancelText: '退出小程序',
					success: (res) => {
						if (res.confirm) {
							setTimeout(() => {
								if (this.$refs.privacyPopup) {
									this.$refs.privacyPopup.open()
								}
							}, 100)
						} else {
							// 退出小程序
							uni.exitMiniProgram()
						}
					}
				})
			},
			goToPrivacy() {
				uni.navigateTo({
					url: '/pages/privacy/privacy'
				})
			},
			startLottery() {
				uni.navigateTo({
					url: '/pages/form/form'
				})
			}
		}
	}
</script>

<style>
	.container {
		display: flex;
		flex-direction: column;
		align-items: center;
		justify-content: center;
		min-height: 100vh;
		background-color: #ffffff;
		padding: 40rpx;
		box-sizing: border-box;
	}

	.content {
		display: flex;
		flex-direction: column;
		align-items: center;
		justify-content: center;
		width: 100%;
	}

	.logo {
		width: 240rpx;
		height: 240rpx;
		margin-bottom: 60rpx;
	}

	.title {
		font-size: 48rpx;
		color: #333;
		font-weight: bold;
		margin-bottom: 30rpx;
		text-align: center;
	}

	.subtitle {
		font-size: 32rpx;
		color: #666;
		text-align: center;
		margin-bottom: 60rpx;
	}
	
	.privacy-popup {
		background-color: #fff;
		border-radius: 20rpx;
		width: 600rpx;
		padding: 40rpx;
	}
	
	.popup-title {
		font-size: 36rpx;
		font-weight: bold;
		text-align: center;
		margin-bottom: 30rpx;
	}
	
	.popup-content {
		max-height: 600rpx;
		margin-bottom: 30rpx;
	}
	
	.content-text {
		font-size: 28rpx;
		color: #666;
		line-height: 1.6;
		margin-bottom: 20rpx;
	}
	
	.privacy-items {
		margin: 20rpx 0;
	}
	
	.privacy-item {
		font-size: 26rpx;
		color: #666;
		line-height: 1.6;
		margin-bottom: 10rpx;
		padding-left: 20rpx;
	}
	
	.privacy-link {
		font-size: 26rpx;
		color: #4a90e2;
		text-align: center;
		margin-top: 20rpx;
	}
	
	.popup-buttons {
		display: flex;
		justify-content: space-between;
		margin-top: 30rpx;
	}
	
	.btn {
		width: 45%;
		height: 80rpx;
		line-height: 80rpx;
		text-align: center;
		border-radius: 40rpx;
		font-size: 28rpx;
	}
	
	.btn-cancel {
		background-color: #f5f5f5;
		color: #666;
	}
	
	.btn-confirm {
		background: linear-gradient(to right, #4a90e2, #357abd);
		color: white;
	}
</style>
